﻿
//扩展自定义jQuery方法
(function($){
	$.extend({
		popShow: function(src) {//src:弹出层内容路径
			if (src) {
				var obj = $('<div class="popbox"><iframe allowtransparency="true" frameborder="0" marginheight="0" scrolling="no" marginwidth="0" width="100%" height="100%" src="' + src + '"></iframe></div>');
				var zzc = $('<div class="zzc"></div>');
				var popPanel = $("body",window.top.document);
				if(window.top.frames["mainFrame"]){
					popPanel = $("#mainFrame",window.top.document).contents().find("body");
				}
				if(!popPanel.find(".popbox").length>0){
                    $(popPanel).append(obj, zzc);
                    obj.animate({
                        right: 0
                    }, 500);
				}
			}
		},
		popHide: function() {
			var topBody = $("body",window.top.document);
			if(!!window.top.frames["mainFrame"]){
					topBody = $("#mainFrame",window.top.document).contents().find("body");
				}
			if (topBody.find(".popbox").length > 0) {
				topBody.find(".popbox").animate({
					right: -674
				}, 500, function() {
					topBody.find(".popbox,.zzc").remove();
				})
			}
		},
		tipShow:function(type,msg){//type：1=成功 2=失败，msg：提示文本
			if(msg&&type){
				var tip=$('<div class="tip">'+msg+'</div>');
				switch(type){
					case 1:
						tip.addClass("success");
					case 2:
						tip.addClass("fail");
				}
				$("body").append(tip);
				tip.fadeIn(500,function(){
					setTimeout(function(){
						tip.fadeOut(500,function(){
							tip.remove()
						});
					},3000)
				});
			}
		},
		confirmShow:function(txt,cb){
			if($.type(txt)=="string"&&$.type(cb)=="function"){
				var confirm=$('<div class="confirm"><a class="close"></a><div class="txt">'+txt+'</div><div class="bt"><a class="cancel">取消</a><a class="pass">确定</a></div></div>');
				var zzc = $('<div class="zzc"></div>'),
					zzc2=$('<div class="zzc2"></div>');
                if ($("body").find(".popbox:visible").length > 0) {
                    $("body").append(zzc2);
                } else {
                    $("body").append(zzc);
                }
				$("body").append(confirm);
				confirm.find(".pass").on("click",cb);
				confirm.find(".close,.cancel,.pass").on("click",function(){
					$.confirmHide();
				})
			}
		},
		confirmHide:function(){
			if($("body").find(".popbox:visible").length>0){
                $(".confirm,.zzc2").remove();
			}
			else{
				$(".confirm,.zzc").remove();
				}
		}

	});
	
	$.fn.extend({
		outerTab : function(obj){
			var params = $.extend({
				tabContentPanel : $("body")
			},obj || {});
			$(".tab-list",$(this)).each(function(index){
				$(this).on("click",function(){
					$(this).addClass("on").siblings().removeClass("on");
					var tabContentItem = $('<div class="tab-content-item"></div>'),
						tabContentPanel = params.tabContentPanel,
						type = $(this).attr("data-type"),
						src = $(this).attr("data-src"),
						iframe_ele = $("<iframe id='iframe"+type+"' width = '100%' height = '100%' frameborder = '0' allowTransparency = 'true' />");
					if(!!tabContentPanel.find("[data-content-type="+type+"]")&&tabContentPanel.find("[data-content-type="+type+"]").length>0){
						tabContentPanel.find("[data-content-type="+type+"]").show().siblings().hide();
					}else{
						tabContentPanel.find(".tab-content-item").hide();
						tabContentItem.height("100%").attr("data-content-type",type)
							.append(iframe_ele.attr("src",src))
							.appendTo(tabContentPanel);
					}
				})
			})
		}
	})
})(jQuery)


